/**
 *  项目名称：
 *  文件说明：
 *  主要特点：
 *  版本号：1.0
 *  制作人：刘晨曦
 *  创建时间：2013-12-3
 **/
package synchronizedTest;

/**
 * @author lcx
 *
 */
public class SynchronizedMultiTest {


	public synchronized void synchronizedMethod(int i)
	{
		System.out.println(i+"  method  start...");
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println(i+"  method  end...");
	}

	public  void synchronizedBlock(int i)
	{
		synchronized(this)
		{
			System.out.println(i+"  block  start...");
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println(i+"  block  end...");
		}
	}


	public static void main(String[] args) {
		final SynchronizedMultiTest test=new SynchronizedMultiTest();
		Thread td1=new Thread()
		{
			int i=0;
			@Override
			public void run()
			{
				while(i++<2)
					test.synchronizedMethod(i);
			}
		};

		Thread td2=new Thread()
		{
			@Override
			public void run()
			{
				int i=2;
				while(i++<6)
					test.synchronizedBlock(i);
			}
		};

		td1.start();
		td2.start();
	}


}
